function asyncFun1(str?: string): Promise<string> {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(`异步执行1${str || ''}`);
    }, 3000);
  });
}

function asyncFun2(str?: string): Promise<string> {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(`异步执行2${str || ''}`);
    }, 2000);
  });
}

function asyncFun3(str?: string): Promise<string> {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(`异步执行3${str || ''}`);
    }, 1000);
  });
}



function callAsyncFunctions3() {
  asyncFun1()
    .then(asyncFun1Res => {
      console.log(asyncFun1Res);
      return asyncFun2(asyncFun1Res);
    })
    .then(asyncFun2Res => {
      console.log(asyncFun2Res);
      return asyncFun3(asyncFun2Res);
    })
    .then(asyncFun3Res => {
      console.log(asyncFun3Res);
    })
    .catch(error => {
      console.error('An error occurred:', error);
    });
}

callAsyncFunctions3();


async function callAsyncFunctions() {
  try {
    const asyncFun1Res = await asyncFun1();
    console.log(asyncFun1Res);

    const asyncFun2Res = await asyncFun2(asyncFun1Res);
    console.log(asyncFun2Res);

    const asyncFun3Res = await asyncFun3(asyncFun2Res);
    console.log(asyncFun3Res);
  } catch (error) {
    console.error('An error occurred:', error);
  }
}

callAsyncFunctions();





